package ad.android.model;

import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import ad.android.util.Constants;

/**
 * TblAd entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "tbl_ad", catalog = Constants.CATALOG)
public class Ad implements java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = -5167969402705201647L;
	private Long id;
	private Set<Area> tblArea;
	private AdType tblAdtype;
	private AdHost tblAdhost;
//	private AdEvent tblAdevent;
	private String adName;
	private String adImgLink;
	private String adClickLink;
	/**
	 * 开始日期
	 */
	private Timestamp addTime;
	/**
	 * 结束日期
	 */
	private Timestamp expiredTime;
	private Float downloadCharge;
	private Float clickCharge;
	private Integer adWeight;
	/**
	 * 关键字
	 */
	private String keywords;
	/**
	 * 描述
	 */
	private String describe;
	/**
	 * 预算类型
	 */
	private Integer budgetType;
	/**
	 * 预算
	 */
	private Double budget;
	private Set<AdApplicationStatistics> tblAdApplicationStatisticses = new HashSet<AdApplicationStatistics>(
			0);

	// Constructors

	/** default constructor */
	public Ad() {
	}



	// Property accessors
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name = "ID", unique = true, nullable = true)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}


	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ADTYPE_ID", nullable = false)
	public AdType getTblAdtype() {
		return this.tblAdtype;
	}

	public void setTblAdtype(AdType tblAdtype) {
		this.tblAdtype = tblAdtype;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ADHOST_ID", nullable = false)
	public AdHost getTblAdhost() {
		return this.tblAdhost;
	}

	public void setTblAdhost(AdHost tblAdhost) {
		this.tblAdhost = tblAdhost;
	}

//	@ManyToOne(fetch = FetchType.LAZY)
//	@JoinColumn(name = "ADEVENT_ID", nullable = false)
//	public AdEvent getTblAdevent() {
//		return this.tblAdevent;
//	}
//
//	public void setTblAdevent(AdEvent tblAdevent) {
//		this.tblAdevent = tblAdevent;
//	}

	@Column(name = "AD_NAME", nullable = false, length = 200)
	public String getAdName() {
		return this.adName;
	}

	public void setAdName(String adName) {
		this.adName = adName;
	}

	@Column(name = "AD_IMG_LINK", length = 1000)
	public String getAdImgLink() {
		return this.adImgLink;
	}

	public void setAdImgLink(String adImgLink) {
		this.adImgLink = adImgLink;
	}

	@Column(name = "AD_CLICK_LINK", length = 1000)
	public String getAdClickLink() {
		return this.adClickLink;
	}

	public void setAdClickLink(String adClickLink) {
		this.adClickLink = adClickLink;
	}

	@Column(name = "ADD_TIME", length = 0)
	public Timestamp getAddTime() {
		return this.addTime;
	}

	public void setAddTime(Timestamp addTime) {
		this.addTime = addTime;
	}

	@Column(name = "EXPIRED_TIME", length = 0)
	public Timestamp getExpiredTime() {
		return this.expiredTime;
	}

	public void setExpiredTime(Timestamp expiredTime) {
		this.expiredTime = expiredTime;
	}

	@Column(name = "DOWNLOAD_CHARGE", precision = 12, scale = 0)
	public Float getDownloadCharge() {
		return this.downloadCharge;
	}

	public void setDownloadCharge(Float downloadCharge) {
		this.downloadCharge = downloadCharge;
	}

	@Column(name = "CLICK_CHARGE", precision = 12, scale = 0)
	public Float getClickCharge() {
		return this.clickCharge;
	}

	public void setClickCharge(Float clickCharge) {
		this.clickCharge = clickCharge;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "tblAd")
	public Set<AdApplicationStatistics> getTblAdApplicationStatisticses() {
		return this.tblAdApplicationStatisticses;
	}

	public void setTblAdApplicationStatisticses(
			Set<AdApplicationStatistics> tblAdApplicationStatisticses) {
		this.tblAdApplicationStatisticses = tblAdApplicationStatisticses;
	}

	@Column(name = "AD_WEIGHT", length=5)
	public Integer getAdWeight() {
		return adWeight;
	}

	public void setAdWeight(Integer adWeight) {
		this.adWeight = adWeight;
	}
	
	@Column(name = "KEYWORDS", length = 255)
	public String getKeywords() {
		return keywords;
	}

	public void setKeywords(String keywords) {
		this.keywords = keywords;
	} 
	@Column(name = "AD_DESC", length = 1000)
	public String getDescribe() { 
		return describe;
	}

	public void setDescribe(String describe) {
		this.describe = describe;
	}
	@Column(name = "BUDGET_TYPE", length = 11)
	public Integer getBudgetType() {
		return budgetType;
	}

	public void setBudgetType(Integer budgetType) {
		this.budgetType = budgetType;
	}
	@Column(name = "BUDGET")
	public Double getBudget() {
		return budget;
	}

	public void setBudget(Double budget) {
		this.budget = budget;
	}


	@ManyToMany(cascade=CascadeType.PERSIST,fetch=FetchType.EAGER)
	@JoinTable(name="AD_AREA",joinColumns=@JoinColumn(name="AD_ID"),
			   inverseJoinColumns={@JoinColumn(name="AREA_ID")})
	public Set<Area> getTblArea() {
		return tblArea; 
	}



	public void setTblArea(Set<Area> tblArea) {
		this.tblArea = tblArea;
	}
	
}